﻿// Study0627.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第六章 数组和指针 实验
//实现两字符串的连接 C风格字符数组与string类分别实现

#include <iostream>
#include <string>
using namespace std;

int main()
{
	//C风格字符数组
	char str1[] = "abc";
	char str2[] = "def";
	cout << "字符串1为：" << str1 << endl;
	cout << "字符串2为：" << str2 << endl;
	int s1 =static_cast<int>( size(str1)) - 1;
	int s2 = static_cast<int>(size(str2)) - 1;
	bool* p;
	int n = sizeof(*p);
	char* mstr = new char[s1 + s2 + 1];
	for (int i = 0; i < s1; ++i)
	{
		mstr[i] = str1[i];
	}
	for (int i = 0; i < s2; ++i)
	{
		mstr[s1 + i] = str2[i];
	}
	mstr[s1 + s2] = '\0';
	cout << "合并后为" << mstr << endl;
	delete[] mstr;

	//string类
	string str11="abc", str22="def";
	cout << "字符串1为：" << str11 << endl;
	cout << "字符串2为：" << str22 << endl;
	cout << "合并后为" << str11+str22 << endl;
	return 0;
}


